package com.danceforyou.user.controller;

import com.danceforyou.common.restful.exception.BizExceptionEnum;
import com.danceforyou.common.util.AssertUtil;
import com.danceforyou.common.util.Constants;
import com.danceforyou.user.model.UserDO;
import com.danceforyou.user.model.UserMenuHiddenDO;
import com.danceforyou.user.service.UserMenuHiddenService;
import com.danceforyou.user.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

/**
 * 类名称：UserMenuHiddenController
 * 创建人：danceforyou
 * 创建时间：2021年01月12日
 * 版本号：1.0v
 */
@RestController
@RequestMapping(value = "/userMenuHidden")
public class UserMenuHiddenController {

    @Autowired
    private UserMenuHiddenService userMenuHiddenService;
	@Autowired(required = false)
	private HttpSession session;

    /**
     * 保存用户页面个性化展示
     * @param menuId 页面ID
     * @param gridId 表格ID
     * @param gridCol 表格列
     * @return boolean
     */
    @RequestMapping(value = "/saveUserMenuHidden", method = RequestMethod.POST)
    public boolean saveUserMenuHidden(String menuId, String gridId, String gridCol) {
        userMenuHiddenService.saveUserMenuHidden(menuId, gridId, gridCol);
	    return true;
    }

    /**
     * 获取用户页面配置
     * @param menuId 页面ID
     * @param gridId 表格ID
     * @return List<UserMenuHiddenDO>
     */
    @RequestMapping(value = "/getUserMenuHidden", method = RequestMethod.GET)
    public List<UserMenuHiddenDO> getUserMenuHidden(String menuId, String gridId) {
        UserVO loginUser = (UserVO) session.getAttribute(Constants.SESSION_USER);
        AssertUtil.notNull(loginUser, BizExceptionEnum.AUTHFAILURE);
        HashMap condition = new HashMap(3){{
            put("userId", loginUser.getId());
            put("menuId", menuId);
            put("gridId", gridId);
        }};
        return userMenuHiddenService.listByCondition(condition);
    }

}
